package com.hejjon.knowledgebase.controller;


import com.hejjon.knowledgebase.annotation.EventLog;
import com.hejjon.knowledgebase.annotation.RestWrapper;
import com.hejjon.knowledgebase.constant.event.EventType;
import com.hejjon.knowledgebase.entity.ExportProperty;
import com.hejjon.knowledgebase.model.request.ExportPropertyRequest;
import com.hejjon.knowledgebase.model.wrapper.DataGrid;
import com.hejjon.knowledgebase.service.ExportPropertyService;
import com.hejjon.knowledgebase.util.ServletsUtil;
import com.hejjon.knowledgebase.util.Valid;
import com.hejjon.knowledgebase.vo.ExportPropertyVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 出库资产表 前端控制器
 * </p>
 *
 * @author caoshi
 * @since 2022-12-12
 */
@Api(value = "资产出库", tags = {"资产出库"})
@RestController
@RestWrapper
@RequestMapping(ServletsUtil.BASE_REQUEST_PATH_PREFIX +"/export/property")
public class ExportPropertyController {

    @Resource
    private ExportPropertyService exportPropertyService;

    @PostMapping("/add")
    @ApiOperation(value = "新增出库资产")
    @EventLog(value = EventType.ADD_ENTRY_PROPERTY)
    public Long addExportProperty(@RequestBody ExportPropertyRequest request){
        Valid.notEmpty(request.getName());
        Valid.notEmpty(request.getClassroom());
        return exportPropertyService.addExportProperty(request);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除出库资产")
    @EventLog(value = EventType.DELETE_ENTRY_PROPERTY)
    public Integer delete(@RequestBody ExportPropertyRequest request){
        List<Long> idList = request.getIdList();
        Valid.notEmpty(idList);
        return exportPropertyService.deleteExportProperty(idList);
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改出库资产")
    @EventLog(value = EventType.UPDATE_ENTRY_PROPERTY)
    public Integer update(@RequestBody ExportPropertyRequest request) {
        Valid.notNull(request.getId());
        return exportPropertyService.updateExportProperty(request);
    }

    @PostMapping("/list")
    @ApiOperation(value = "获取资产出库列表")
    public DataGrid<ExportPropertyVO> listExportProperty(@RequestBody ExportPropertyRequest request) {
        return exportPropertyService.listExportProperty(request);
    }

    @PostMapping("/get")
    @ApiOperation(value = "根据id获取出库资产")
    public ExportProperty getExportProperty(@RequestBody ExportPropertyRequest request){
        Long id = Valid.notNull(request.getId());
        return exportPropertyService.getExportProperty(id);
    }
}

